from CvPythonExtensions import *

from PlanetfallSpells import PlanetfallSpellPlotTargetBase
import PlanetfallSpellsUtils as PSUtils

gc = CyGlobalContext()

EARTHQUAKE_CAST_RANGE = 4

class Earthquake(PlanetfallSpellPlotTargetBase):
    def __init__(self):
        PlanetfallSpellPlotTargetBase.__init__(self)

        self.pCastingUnits = []
        # Fill list with units that can cast, such as..
        #self.pCastingUnits.append( gc.getInfoTypeForString("UNIT_NAME_1") )
        #self.pCastingUnits.append( gc.getInfoTypeForString("UNIT_NAME_2") )

    def canUnitCast(self, pCastingUnit, pCastingPlot, bVisible):
        if not pCastingUnit.getUnitType() in self.pCastingUnits:
            return False
        
        return True

    def getRangePlots(self, pCastingGroup, pCastingPlot, pHoverPlot):
        pRangePlots = PSUtils.getRangePlotDistanceList(pCastingPlot, EARTHQUAKE_CAST_RANGE)
        return pRangePlots
        

    def canTargetPlot(self, pCastingGroup, pCastingPlot, pPotentialPlot):
        if not PSUtils.isPlotDistanceInRange(pCastingPlot, EARTHQUAKE_CAST_RANGE, pPotentialPlot):
            return False

        if not pPotentialPlot.isVisible(pCastingGroup.getTeam(), False):
            return False

        return True


    def startSpellResultsOnPlot(self, pCastingGroup, pPlot):
        CyEngine().triggerEffect( gc.getInfoTypeForString("EFFECT_RES_BOMB"), pPlot.getPoint() )
